package ui;

import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;


//纯UI类无对外接口
public class LeftButton extends Label {
	
	static LeftButton currentButton;
	protected Image deactive;
	protected Image active;
	protected Image actived;
	protected LeftButton thisObj;
	protected AbstractUI bandingUI;

	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public LeftButton(Composite parent, int style) {
		super(parent, style);
		thisObj = this;
	}

	void initail(String deactive, String active, String actived) {
		this.deactive = new Image(getDisplay(), deactive);
		this.active = new Image(getDisplay(), active);
		this.actived = new Image(getDisplay(), actived);
		addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				if(thisObj != currentButton) {
					thisObj.active();
				}
			}
		});
		addMouseTrackListener(new MouseTrackAdapter() {
			@Override
			public void mouseEnter(MouseEvent e) {
				if(thisObj != currentButton) {
					thisObj.setImage(thisObj.active);
				}
			}
			
			@Override
			public void mouseExit(MouseEvent e) {
				if(thisObj != currentButton) {
					thisObj.setImage(thisObj.deactive);
				}
			}
		});
		setImage(thisObj.deactive);
	}
	
	void active() {
		if (currentButton != null) {
			currentButton.deactive();
			
		}
		ui.global.Current.getUI().setVisible(false);
		currentButton = thisObj;
		bandingUI.active();
		ui.global.Current.setUI(bandingUI);
		setImage(actived);
		
	}

	void deactive() {
		if (currentButton != null) {
			setImage(deactive);
		}
	}

	public AbstractUI getBandingUI() {
		return bandingUI;
	}

	public void setBandingUI(AbstractUI bandingUI) {
		this.bandingUI = bandingUI;
	}

	@Override
	protected void checkSubclass() {
	}

}
